var mongoose = require('mongoose');
var config = require('./config');

mongoose.connect(config.DB);

//数据库连接成功
mongoose.connection.on("connected",function(){
	console.log('Mongoose connected to '+config.DB);
});

//数据库连接错误
mongoose.connection.on("error",function(err){
	console.log('Mongoose connection error:'+err.message);
});

//数据库断开连接
mongoose.connection.on("disconnected",function(){
	console.log("Mongoose disconnected");
});

//系统服务中断
process.on("SIGINT",function(){
	mongoose.connection.close(function(){
		console.log("Mongoose default connection disconnected through app termination");
		process.exit(0);
	});
});

module.exports = mongoose;